package com.eques.bean

import com.eques.service.DoorBellService
import java.text.SimpleDateFormat
import java.util.*

data class RingRecord(
    val fid: String,                    // 文件ID
    val has_preview: Int,               // 是否有预览图
    val ringtime: Long,                 // 响铃时间戳
    val face_score: Int,                // 人脸评分
    val op_type: Int,                   // 操作类型（开锁方式）
    val bid: String                     // 设备ID
) {

    /**
     * 获取开锁方式描述
     */
    fun getOpenLockMethod(): String {
        return when (op_type) {
            0 -> "门铃呼叫"
            1 -> "室内来电"
            else -> "未知方式"
        }
    }

    /**
     * 获取格式化时间
     */
    fun getFormattedTime(): String {
        val date = Date(ringtime)
        val now = Date()
        val diff = now.time - ringtime

        return when {
            diff < 60 * 1000 -> "刚刚"
            diff < 60 * 60 * 1000 -> "${diff / (60 * 1000)}分钟前"
            diff < 24 * 60 * 60 * 1000 -> "${diff / (60 * 60 * 1000)}小时前"
            else -> {
                val sdf = SimpleDateFormat("MM月dd日 HH:mm", Locale.getDefault())
                sdf.format(date)
            }
        }
    }

    /**
     * 生成缩略图URL（根据实际接口调整）
     */
    fun getThumbnailUrl(): String {
      return  DoorBellService.icvss!!.equesGetRingPictureUrl(fid, bid, "", "preview_id").toString();
//        return "https://your-server.com/thumbnail/$fid" // 替换为实际URL
    }
}

/**
 * 门铃列表响应数据
 */
data class RingListResponse(
    val reason: String,
    val total: Int,
    val code: Int,
    val method: String,
    val offset: Int,
    val max: Int,
    val limit: Int,
    val context: String,
    val list: List<RingRecord>
)